<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="积分所属人">
              <j-input placeholder="请输入积分所属人" v-model="queryParam.ownerName" type="txt"/>
            </a-form-item>
            <a-form-item label="所属人部门">
              <j-select-depart placeholder="请选择所属人部门" v-model="queryParam.ownerDeptId"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="归属年份">
              <j-date placeholder="请选择归属年份" v-model="queryParam.year" date-format="YYYY" mode="year" @yearChange="handleYearChange"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">积分录入</a-button>
      <a-button v-has="'score:upload'" v-if="downloadFlag" type="primary" icon="download" @click="handleExportXls('积分详情表')">导出</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button v-if="adminFlag" style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-button type="link" v-has="'score:auth'" :disabled="['2', '3', '4'].includes(record.authStatus)" @click="handleDetail(record, 'auth')">审核</a-button>
          <a-divider v-has="'score:auth'" type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record, 'check')">详情</a>
              </a-menu-item>
              <a-menu-item v-if="['0', '1', '3', '4'].includes(record.authStatus) && !adminFlag">
                <a @click="handleEdit(record, 'edit')">编辑</a>
              </a-menu-item>
              <a-menu-item v-if="adminFlag">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <score-inf-modal ref="modalForm" @ok="modalFormOk"></score-inf-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ScoreInfModal from './modules/ScoreInfModal'
  import { filterDictTextByCache } from '@comp/dict/JDictSelectUtil'
  import { mapState } from 'vuex'

  export default {
    name: 'ScoreInfList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ScoreInfModal
    },
    data () {
      return {
        description: '积分详情表管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'积分所属人',
            align:"center",
            dataIndex: 'ownerId_dictText'
          },
          {
            title:'所属人部门',
            align:"center",
            dataIndex: 'ownerDeptId_dictText'
          },
          {
            title:'申请人',
            align:"center",
            dataIndex: 'createdId_dictText'
          },
          {
            title:'积分类型',
            align:"center",
            dataIndex: 'scoreType',
            customRender:function (text) {
              return filterDictTextByCache('score_type', text)
            }
          },
          {
            title:'积分描述',
            align:"center",
            dataIndex: 'scoreDesc'
          },
          {
            title:'拟申请积分分数',
            align:"center",
            dataIndex: 'scoreValue'
          },
          {
            title:'归属年份',
            align:"center",
            sorter: true,
            dataIndex: 'year',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'是否已兑付奖励',
            align:"center",
            dataIndex: 'isUsed',
            customRender:function (text) {
              return filterDictTextByCache('yn', text)
            }
          },
          {
            title:'审核状态',
            align:"center",
            dataIndex: 'authStatus',
            customRender:function (text) {
              return filterDictTextByCache('auth_status', text)
            }
          },
          {
            title:'审核说明',
            align:"center",
            dataIndex: 'authDesc'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/score/scoreInf/queryPageListByUser",
          delete: "/score/scoreInf/delete",
          deleteBatch: "/score/scoreInf/deleteBatch",
          exportXlsUrl: "/score/scoreInf/export",
          importExcelUrl: "score/scoreInf/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
      ...mapState({
        device: state => state.app.device,
        authList: state => state.user.authList
      }),
      downloadFlag() {
        return this.device === 'desktop'
      },
      adminFlag() {
        const adminFlag = this.authList.findIndex((item) => item.action === 'score:admin')
        return adminFlag > -1
      }
    },
    methods: {
      handleYearChange(val) {
        this.$set(this.queryParam, 'year', val.format('YYYY'))
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'sel_user',value:'ownerId',text:'积分所属人'})
        fieldList.push({type:'string',value:'ownerName',text:'所属人姓名',dictCode:''})
        fieldList.push({type:'sel_depart',value:'ownerDeptId',text:'所属人部门'})
        fieldList.push({type:'string',value:'ownerDeptName',text:'所属人部门名称',dictCode:''})
        fieldList.push({type:'sel_user',value:'createdId',text:'申请人'})
        fieldList.push({type:'string',value:'createdName',text:'申请人姓名',dictCode:''})
        fieldList.push({type:'sel_search',value:'scoreType',text:'积分类型',dictTable:"", dictText:'', dictCode:'score_type'})
        fieldList.push({type:'string',value:'scoreDesc',text:'积分描述',dictCode:''})
        fieldList.push({type:'string',value:'scoreValue',text:'拟申请积分分数',dictCode:''})
        fieldList.push({type:'string',value:'evidenceUrl',text:'证明材料url',dictCode:''})
        fieldList.push({type:'date',value:'year',text:'归属年份'})
        fieldList.push({type:'string',value:'isUsed',text:'是否已兑付奖励',dictCode:'yn'})
        fieldList.push({type:'string',value:'authStatus',text:'审核状态',dictCode:'auth_status'})
        fieldList.push({type:'string',value:'authDesc',text:'审核说明',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
<style lang="less" scoped>
  /deep/ .ant-btn-link{
    padding: 0
  }
</style>